package com.ljh.onlinetest.domain.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ljh
 * @ClassName RoleEnum.java
 * @createTime 2021年12月30日
 */
public enum RoleEnum {
    STUDENT(1,"STUDENT"),
    ADMIN(3,"ADMIN")
    ;
    int code;
    String name;

    private static final Map<Integer,RoleEnum> keyMap = new HashMap<>();

    static {
        for (RoleEnum value : RoleEnum.values()) {
            keyMap.put(value.getCode(),value);
        }
    }

    public static RoleEnum formCode(Integer code){
        return keyMap.get(code);
    }

    RoleEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoleName() {
        return "ROLE_" + name;
    }
}
